/**
 * File:   AddNodeAction.java
 * Author: Gvennet
 */
package gui.actions;

import dht.network.Network;
import gui.main.AddNodeDialog;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;

/**
 * todo write javadoc
 */
public final class AddNodeAction extends AbstractAction
{

	private final JFrame frame;

	private final Network network;

	public AddNodeAction(JFrame frame, Network network)
	{
		super("+");
		putValue(SHORT_DESCRIPTION, "Добавить узел");
		putValue(MNEMONIC_KEY, KeyEvent.VK_A);
		this.frame = frame;
		this.network = network;
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		if (AddNodeDialog.showDialog(frame, "Добавить узел").equals("Ok"))
		{
			try
			{
				network.sendPingRequest(AddNodeDialog.getIpAddress(), AddNodeDialog.getPort());
			}
			catch (IOException e1)
			{
				throw new RuntimeException(e1); //todo
			}
		}


	}
}
